Skip to content

DEV-1123: take the pressure sensor from SD header byte 224 - #313

Merged
MAzalya merged 3 commits into
masterfrom
DEV-1123_sd_header_pressure_id
Oct 5, 2026
Merged

MAzalya merged 3 commits into
masterfrom
DEV-1123_sd_header_pressure_id

Conversation

@marknolan

@marknolan marknolan commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Driver half of the Java parser change for DEV-1123.

Stacked on #311 (DEV-1110), so its base is that branch, and it builds on DEV-1110's in-band sensor-ID override. Once #311 merges, GitHub retargets this PR to master. The SD parser that calls it is in ShimmerResearch/Shimmer-Advance-API#490. Firmware: ShimmerResearch/log-and-stream-common#142.

The byte

LogAndStream now records the detected pressure part at SD header offset 224:

  • Bits 0–6: the 0xA7 sensor ID (4–0x7D reserved for future parts).
  • Bit 7: inferred from the SR number because the chip-ID check was inconclusive.
  • 0xFE: no sensor fitted.
  • 0xFF: not recorded, i.e. older firmware.

Changes

  • New sensors/bmpX80/SdHeaderPressureSensorId: a small pure helper.
    • parse(svo, byte) returns ABSENT, KNOWN, UNKNOWN or NOT_FITTED, plus the sensor ID and the inferred flag.
    • isSupported(svo) is the gate: LogAndStream, plus either Shimmer3R ≥ v1.01.018 or Shimmer3 ≥ v1.01.006.
    • A known ID that this hardware has no code path for counts as UNKNOWN: BMP180/280 on a Shimmer3R, or BMP390/581 on a Shimmer3.
  • ShimmerObject:
    • setPressureSensorIdFromSdHeader(int). The ID is cleared with the board details, like DEV-1110's in-band ID.
    • isSupportedBmp581() honours the header ID after the in-band ID, and isSupportedBmp280() gains the equivalent override on Shimmer3.
    • The Shimmer3 barometer class follows isSupportedBmp280(). Without a header ID that's the same as before, because it delegates to the same IMU-generation rule.
    • For an unknown ID or 0xFE, buildMsg skips pressure calibration via isPressureSensorCalibratable(), so the multimap gets only UNCAL. The calibrated arrays (the arrays data structure and the parallel mCalData) get NaN, not 0. There is no SR-rule fallback.
    • Logging: a disagreement with the SR rule goes to consolePrintLn; inferred and unknown go to consolePrintErrLn.
    • New getters: isPressureSensorInferred() and getPressureSensorIdSdHeader().
    • SdHeaderPressureSensorId is Serializable, because ShimmerObject holds one and ShimmerPC.deepClone() serialises the device.
  • Known limitation: for an unknown or absent sensor the uncalibrated channels keep the platform's base names (BMP390 on Shimmer3R, BMP180 on Shimmer3). The driver has no part-neutral pressure channel name, and adding one is a larger refactor.

Found along the way (not changed here)

ShimmerVerObject.compareVersions(svo, hardwareVersion, …) ignores its hardware argument (ShimmerVerObject.java:695-697). So the gate goes to UtilShimmer.compareVersions directly, which does check the hardware. Fixed separately in #314 (merged).

Testing

  • New API_00022_SdHeaderPressureSensorIdTest (10 tests): decoding, the inferred bit, unknown and none, wrong-platform IDs, serialisation, and a hardware-aware gate. The gate test checks that a Shimmer3R at v1.1.6–1.1.17 does not pass and a Shimmer3 at 1.1.18 does.
  • New API_00023_SdHeaderPressureSensorIdShimmerPCTest (ShimmerDriverPC, 3 tests): deepClone() for every header state, and buildMsg in both data structures: NaN for an unknown or not-fitted sensor, real values for a known one.
  • cd ShimmerDriver && ./gradlew test: 123 tests, 0 failures. cd ShimmerDriverPC && ./gradlew build (the CI command, through the Shimmer-Java-Android-API-named junction): 32 ShimmerDriverPC tests, 0 failures.
  • The Advance API PR's ShimmerDriverAdvanced tests against this branch: 19 tests, 0 failures.
  • End-to-end SD tests live in the Advance API PR.

🤖 Generated with Claude Code

LogAndStream now records the pressure sensor it found at SD header offset
224: bits 0-6 a PRESSURE_SENSOR_ID (the 0xA6 numbering), bit 7 "inferred
from the SR number", 0xFE none fitted, 0xFF not recorded. The new
SdHeaderPressureSensorId decodes it and gates it on the firmware:
LogAndStream on Shimmer3R v1.01.018+ or Shimmer3 v1.01.006+. The gate
checks the hardware version because the two version lines overlap; it goes
to UtilShimmer directly since ShimmerVerObject.compareVersions(svo, hw, ...)
ignores its hardware argument.

ShimmerObject.setPressureSensorIdFromSdHeader() records the decoded byte,
for ShimmerSDLog to call between setting the board and building the sensor
classes. When present it overrides the SR-number rule:
- isSupportedBmp581() consults it after DEV-1110's in-band ID (Shimmer3R).
- isSupportedBmp280() consults it (Shimmer3), and the Shimmer3 barometer
  class now follows isSupportedBmp280() rather than the IMU generation,
  which is the same thing unless the header says otherwise.
- An unknown ID, a sensor the platform has no parser path for (BMP180/280
  on a Shimmer3R, BMP390/581 on a Shimmer3) or 0xFE leaves the pressure and
  temperature channels uncalibrated: buildMsg skips calibration when
  isPressureSensorCalibratable() is false. There is no SR-number fallback;
  the base sensor class (BMP390 / BMP180) is kept only to name and lay out
  the channels.
A disagreement with the SR-number rule is logged, and an inferred or
unknown ID is warned about. isPressureSensorInferred() lets a caller warn
too. Like the in-band ID, it is cleared when the board details change.

API_00022 covers the decoding and the gate. API_00012-00021 are all taken
across branches, hence 22. Choosing the sensor against the SR-number rule
is tested end to end through ShimmerSDLog in Shimmer-Advance-API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Header-state serialization and array-backed calibrated output need correction before approval.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Builds on DEV-1110 to use SD header byte 224 for pressure-sensor selection instead of relying solely on board revisions.

Changes:

  • Adds hardware-aware header decoding and firmware gates.
  • Applies sensor overrides and skips calibration for unsupported or unfitted sensors.
  • Adds decoding and version-boundary tests.
File Description
ShimmerDriver/​src/​test/​java/​com/​shimmerresearch/​driver/​API_00022_SdHeaderPressureSensorIdTest.java Tests header states, sensor IDs, and firmware gates.
ShimmerDriver/​src/​main/​java/​com/​shimmerresearch/​sensors/​bmpX80/​SdHeaderPressureSensorId.java Decodes the pressure-sensor header byte.
ShimmerDriver/​src/​main/​java/​com/​shimmerresearch/​driver/​ShimmerObject.java Integrates header-based selection, calibration gating, logging, and state reset.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…alibrated

Review fixes (Copilot, #313):

- SdHeaderPressureSensorId is now Serializable. ShimmerObject holds one
  in a non-transient field once setPressureSensorIdFromSdHeader() has
  run, even for an absent header, and ShimmerPC.deepClone() serialises
  the device: it hit NotSerializableException and returned null.

- When the SD header names a sensor the parser cannot calibrate, or none
  fitted, the calibrated pressure and temperature entries are now NaN
  rather than the array's default 0. The multimap already read NaN,
  having no CAL entry, but the arrays data structure and the parallel
  mCalData exposed 0 kPa and 0 degC as if they were readings.

API_00022 round-trips each state through serialisation. The new
API_00023 (ShimmerDriverPC) deep-clones a device for every header state,
and runs buildMsg in both data structures: NaN for an unknown or
not-fitted sensor, real values for a known one. Both fail without the
fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@MAzalya
MAzalya changed the base branch from DEV-1110_bmp581_inband_sensor_id to master October 5, 2026 03:15

@MAzalya MAzalya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok tested, all looks good

@MAzalya
MAzalya merged commit f95ff52 into master Oct 5, 2026
2 checks passed
@MAzalya
MAzalya deleted the DEV-1123_sd_header_pressure_id branch October 5, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants